
package com.xmzs.web.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import com.xmzs.common.core.domain.R;
import com.xmzs.common.gpt.entity.whisper.WhisperResponse;
import com.xmzs.common.gpt.openai.OpenAiStreamClient;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;


/**
 * AI对话
 *
 * @author: wangle
 * @date: 2023/7/6
 */


@SaIgnore
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/chat")
public class ChatController {

    private final OpenAiStreamClient openAiStreamClient;

    /**
     * 语音转为文字
     *
     * @param file
     * @return R<KeyInfo>
     * @Date 2023/7/10
     **/

    @PostMapping("/speechToTextTranscriptions")
    public R<String> speechToTextTranscriptions(File file) {
        WhisperResponse whisperResponse = openAiStreamClient.speechToTextTranscriptions(file);
        return R.ok(whisperResponse.getText());
    }

}

